//
//  TouchView.m
//  UI28_target_action
//
//  Created by Scott on 16/1/20.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "TouchView.h"

@interface TouchView ()

/** 声明两个属性, 分别是target 和 action */
@property (nonatomic, assign) id target;

@property (nonatomic, assign) SEL action;

@end

@implementation TouchView


#pragma mark - 知识点 target/action设计模式.
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    // 让target执行action方法.
    [self.target performSelector:self.action withObject:self afterDelay:0];
    
}


- (void)addTarget:(id)target action:(SEL)action {
    
    self.target = target;
    self.action = action;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
